﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business.UnitTests
{

	/// <summary>
	/// Unit tests for the <see cref="AttributeAveragingCounter"/> class.
	/// </summary>
	[TestClass]
	public class AttributeAveragingCounterFixture
	{

		#region Methods

		/// <summary>
		/// Tests all methods and properties of the counter.
		/// </summary>
		[TestMethod]
		public void TestAttributeAveragingCounterOperation()
		{
			AttributeAveragingCounter counter;
			Guid attribute1Id;
			Guid attribute2Id;
			Dictionary<Guid, double> averages;

			counter = new AttributeAveragingCounter();
			Assert.AreEqual(0, counter.Averages.Count);

			attribute1Id = Guid.NewGuid();
			counter.AddValue(attribute1Id, 1);
			counter.AddValue(attribute1Id, 2);
			counter.AddValue(attribute1Id, 1);
			averages = counter.Averages;
			Assert.AreEqual(1, averages.Count); // 1 attribute so far
			Assert.IsTrue(averages.ContainsKey(attribute1Id));
			Assert.AreEqual(1.33d, Math.Round(averages[attribute1Id], 2));

			attribute2Id = Guid.NewGuid();
			counter.AddValue(attribute2Id, 2);
			counter.AddValue(attribute2Id, 4);
			counter.AddValue(attribute2Id, 2);
			counter.AddValue(attribute2Id, 0);
			averages = counter.Averages;
			Assert.AreEqual(2, averages.Count); // 2 attributes now
			Assert.IsTrue(averages.ContainsKey(attribute2Id));
			Assert.AreEqual(2.0d, Math.Round(averages[attribute2Id], 2));

			counter.Reset();
			Assert.AreEqual(0, counter.Averages.Count);
		}

		#endregion // Methods

	}

}
